package com.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.InsectPestBean;
import com.project.dao.InsectPestDao;
import com.project.service.InsectPestService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 虫害
 */
@Service
@Transactional
public class InsectPestServiceImpl extends ServiceImpl<InsectPestDao, InsectPestBean> implements InsectPestService {
    @Override
    public IPage<InsectPestBean> findAllInsectPest(int pageNO, int pageSize) {
        Page<InsectPestBean> page = new Page<>(pageNO,pageSize);
        IPage<InsectPestBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addInsectPest(InsectPestBean insectPest) {
        this.baseMapper.addInsectPest(insectPest);
    }

    @Override
    public InsectPestBean findId(int insectPestId) {
        return this.baseMapper.findId(insectPestId);
    }

    @Override
    public IPage<InsectPestBean> findName(int pageNO, int pageSize, String insectPestName, String insectPestHost) {
        Page<InsectPestBean> page = new Page<>(pageNO,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (insectPestName!=null && !insectPestName.equals("")){
            wrapper.like("insectPest_name",insectPestName);
        }
        if (insectPestHost!=null && !insectPestHost.equals("")){
            wrapper.like("insectPest_host",insectPestHost);
        }
        IPage<InsectPestBean> iPage = this.page(page,wrapper);
        return iPage;
    }
}
